package model.trader;


import model.market.MarketConfig;
import model.market.MarketInformation;
import model.market.MarketManager;
import model.market.Position;
import model.market.Trade;
import model.trader.TradeInstruction.IndicativePricePair;
import model.trader.portfolio.PortfolioManagementStrategy;
import model.trader.trade.DemandCurveStrategy;
import model.trader.trade.LiquidityAdjustingExecutionStrategy;
import model.trader.trade.TradeExecutionStrategy;

//AMLOW: think about risk manager to prevent trade strategy cock up.
public abstract class BaseTrader implements Trader{
	
	private LiquidityAdjustingExecutionStrategy liquidityAdjustedTrader=new LiquidityAdjustingExecutionStrategy();
	private DemandCurveStrategy emhTrader=new DemandCurveStrategy();

	public abstract TradeExecutionStrategy getTradeStrategy();
	
	public abstract PortfolioManagementStrategy getPortfolioStrategy();

	/**
	 * .
	 * @param marketInfo
	 * @return
	 */
	public abstract double[] getPreferences(MarketManager market,MarketInformation marketInfo);
	
	@Override
	public java.util.List<Trade> trade(MarketManager market, Position position,
			MarketInformation marketInfo) {
		
		double[] preferences = getPreferences(market,marketInfo);
		TradeInstruction[] allocate = getPortfolioStrategy()
					.allocate(position, market, preferences,marketInfo);
		TradeExecutionStrategy tradeStrategy = getTradeStrategy();
		if(tradeStrategy==null){
			switch(market.getConfig().getTradeStrategy()){
				case MarketConfig.TRADE_STRAT_ADJ:
					tradeStrategy=liquidityAdjustedTrader;
					break;
				case MarketConfig.TRADE_STRAT_EMH:
					tradeStrategy=emhTrader;
					break;
				default:
					throw new RuntimeException("Unexpected trade strategy config: "+market.getConfig().getTradeStrategy());
			}
		}
		return tradeStrategy.trade(this,position, allocate, market,marketInfo);
		
	}
	
}
